﻿using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;

namespace SweetSQL.Data
{
    internal sealed class TableInfo
    {
        public bool Reflected = false;
        public Type Type = null;
        public string Name = null;
        public TableAttribute Attribute = null;
        public PropertyInfo Property = null;

        public TableInfo()
        {
            Columns = new List<ColumnInfo>();
            PrimaryKeys = new List<ColumnInfo>();
            ForeignKeys = new List<ColumnInfo>();
            ColumnLookup = new Dictionary<string, ColumnInfo>();
        }

        public List<ColumnInfo> Columns
        {
            get;
            private set;
        }

        public List<ColumnInfo> PrimaryKeys
        {
            get;
            private set;
        }

        public List<ColumnInfo> ForeignKeys
        {
            get;
            private set;
        }

        public Dictionary<string, ColumnInfo> ColumnLookup
        {
            get;
            private set;
        }

        public void Add(ColumnInfo info)
        {
            Columns.Add(info);
            if (info.Attribute.IsPrimaryKey)
            {
                PrimaryKeys.Add(info);
            }
            if (info.Attribute.IsForeignKey)
            {
                ForeignKeys.Add(info);
            }
            ColumnLookup.Add(info.Name, info);
        }
    }
}
